#运动控制库
#-DBUILD_MOTION_DEMO=true          #build demo(default false)
#-DCMAKE_BUILD_TYPE=Debug   #build debug(default release)
cmake_minimum_required(VERSION 2.8)

PROJECT(robots_kdl)


#版本信息
SET( MOTION_VERSION 1.1.1)
STRING( REGEX MATCHALL "[0-9]+" MOTION_VERSIONS ${MOTION_VERSION})
LIST( GET MOTION_VERSIONS 0 MOTION_VERSION_MAJOR)
LIST( GET MOTION_VERSIONS 1 MOTION_VERSION_MINOR)
LIST( GET MOTION_VERSIONS 2 MOTION_VERSION_PATCH)
add_definitions(-DCVERSION="${MOTION_VERSION}")
MESSAGE( "motion9 version ${VERSION} (${MOTION_VERSION_MAJOR}.${MOTION_VERSION_MINOR}.${MOTION_VERSION_PATCH})" )

find_package(Eigen 3 QUIET)
if(NOT Eigen_FOUND)
  include(${CMAKE_SOURCE_DIR}/robot_kdl/orocos_kinematics_dynamics/orocos_kdl/config/FindEigen3.cmake)
  set(Eigen_INCLUDE_DIR "${EIGEN3_INCLUDE_DIR}")
endif()
include_directories(${Eigen_INCLUDE_DIR})

#bulid type
if(NOT DEFINED CMAKE_BUILD_TYPE)
	set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type")
else()
	#DEBUG 模式添加DEBUG宏
	set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type")
	ADD_DEFINITIONS(-DDEBUG)
endif()
message(STATUS "build type is " ${CMAKE_BUILD_TYPE})

#添加源文件目录,源文件,头文件
#include head
include_directories(./src ../src/joint_controller ./src/kinematics ./src/trajectory_plane ../robot_kdl/orocos_kinematics_dynamics/orocos_kdl/src 
../robot_kdl/robots_kdl/src 
${CMAKE_CURRENT_BINARY_DIR}/../robot_kdl/orocos_kinematics_dynamics/orocos_kdl/src)

#source
aux_source_directory(./src motion_dll_src1)
aux_source_directory(./src/joint_controller motion_dll_src2)
aux_source_directory(./src/kinematics  motion_dll_src3)
aux_source_directory(./src/trajectory_plane motion_dll_src4)

#生成motion9_dll动态库
add_library(motion9_dll SHARED ${motion_dll_src1} ${motion_dll_src2} ${motion_dll_src3} ${motion_dll_src4})
SET_TARGET_PROPERTIES( motion9_dll PROPERTIES
SOVERSION "${MOTION_VERSION_MAJOR}.${MOTION_VERSION_MINOR}"
VERSION "${MOTION_VERSION}"
INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}"
PUBLIC_HEADER ./src/motion9_dll.h)
TARGET_LINK_LIBRARIES(motion9_dll robots_kdl)

#example
OPTION(BUILD_MOTION_DEMO "buidl demo" FALSE) 
if(BUILD_MOTION_DEMO)
	if (CMAKE_SYSTEM_NAME MATCHES "Linux")
		set(motion_dll_example_src ./test_src/test_motion_linux.cpp)
		add_executable(test_motion ${motion_dll_example_src})
		target_link_libraries(test_motion motion9_dll -lpthread)
	elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
		set(motion_dll_example_src ./test_src/test_motion9.cpp 
		./test_src/stdafx.cpp)
		add_executable(test_motion ${motion_dll_example_src})
		target_link_libraries(test_motion motion9_dll)
	endif()
	message(STATUS "build demo test_motion")
	install( TARGETS motion9_dll test_motion
    	RUNTIME DESTINATION bin
    	ARCHIVE DESTINATION lib${LIB_SUFFIX}
    	LIBRARY DESTINATION lib${LIB_SUFFIX}
    	PUBLIC_HEADER DESTINATION include
  	)
else()
	message(STATUS "skip build demo")
	install( TARGETS motion9_dll
		RUNTIME DESTINATION bin
		ARCHIVE DESTINATION lib${LIB_SUFFIX}
		LIBRARY DESTINATION lib${LIB_SUFFIX}
		PUBLIC_HEADER DESTINATION include
  	)
endif()

